/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
Ext.chart.Chart.CHART_URL = '../../../ext3/resources/charts.swf';
Ext.QuickTips.init();
var _pageSize = 20;
var _title = '监测点月数据';
var store;
var now = new Date();
var loadPointServlet = basePath + 'servlet/system/PointLoad';
var loadServlet = '../../../servlet/data/YsjLoad';
var saveServlet = '../../../servlet/data/YsjSave';


var fieldName = ['id', 'code', 'name', 'pointTypeId', 'pointType', 'pointType2Id', 'pointType2', 'voltageLevelId', 'voltageLevelName', 'status',
    'orgCode', 'deptId', 'fromId', 'lowerLimit', 'upperLimit', 'pointArea', 'pointPosition', 'userName', 'publicName', 'company', 'installSite',
    'subCompany', 'shortName', 'stationVoltageLevel', 'reportStatusCh', "startStatus"];


var tabs = new Ext.TabPanel({
    activeTab: 0,
    plain: true,
    enableTabScroll: true,
    defaults: {autoScroll: true},
    items: [{
            title: currentOrgName + '监测点',
            id: 'main-tab',
            layout: "fit",
            tbar: new Ext.Toolbar([
                {
                    text: '5分钟电压对比图形',
                    handler: show5mChart
                            , style: {marginLeft: '10px'}
                },
                {
                    text: '日合格率对比图形',
                    handler: showDayRateChart
                            , style: {marginLeft: '10px'}
                },
                {
                    text: '月合格率对比图形',
                    handler: showMonthRateChart
                            , style: {marginLeft: '10px'}
                }
            ]),
            listeners: {
                'render': function() {
                    tbarPoint.render(this.tbar);
                }
            }
        }
    ]
});




function createConnectPointStore() {
    var storeSuperior = new Ext.data.JsonStore({
        url: loadPointServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: false,
        baseParams: {cmd: "superior"}
    });
    var storeJunior = new Ext.data.JsonStore({
        url: loadPointServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: false,
        baseParams: {cmd: "junior"}
    });
    var storeSibling = new Ext.data.JsonStore({
        url: loadPointServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: false,
        baseParams: {cmd: "sibling"}
    });
    
    return {storeSuperior:storeSuperior,storeJunior:storeJunior,storeSibling:storeSibling};
}


function create5MCategoryArray() {    
    var categories = [];
    var hour=0;
    var min=0;
    var shour;
    var smin;
    for (var i = 0; i < 24*60/5; i++) {
        if(hour<10){
            shour='0'+hour;
        }else{
            shour=''+hour;
        }
        if(min<10){
            smin="0"+min;
        }else{
            smin=''+min;
        }            
        var stime = shour+":"+smin;
        categories.push(stime);
        min=min+5;
        if(min>=60){
            hour=hour+1;
            min=min%60;
        }
    }
    return categories;
}

function request5mData(charts, i, mainPointId,pointId,cmd) {
    var date = Ext.getCmp('datefive'+mainPointId).getValue().format('Y-m-d');
    
    Ext.Ajax.request({
        url: '../../../servlet/data/HighChartsDataServlet',
        success: function(response, options) {
            var obj = Ext.decode(response.responseText);
            charts.series[i].setData(obj);
        },
        failure: function(response, opts) {
            Ext.Msg.alert('系统提示', '加载数据错误: ' + response.status);
        },
        params: {pointId: pointId,cmd:cmd,date:date}
    });
}

function show5mChart() {    
    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择监测点");
        return;
    }
    var record = checkboxSel.getSelected();
    var mainPointId = record.get('id');
    var mainPointName= record.get('name');
    var vid = mainPointName + ' 5分钟数据';

    var stores = createConnectPointStore();
    
    var middle5mPanel = new Ext.Panel({
        //height: '40%',
        region: 'center',
        id:'mfive'+mainPointId,
        html: '<div id="chartfive'+mainPointId+'" style="min-width: 400px; min-height: 300px; margin: 0 auto"></div>'
    });    


    function addAxis(s,ri,r){
        var pointName = r.get('name');
        var pointId=r.get('id');
        charts.addAxis({
                        id: 'axis'+mainPointId+pointId,
                        title: {
                            text: null
                        },
                        lineWidth: 1                       
                    });
        charts.addSeries({
            name: pointName,
            id: 's'+mainPointId + pointId,
            yAxis: 'axis'+mainPointId+pointId,
            data: []
        });
        charts.series[charts.series.length-1].pointId = pointId;
        request5mData(charts, charts.series.length-1, mainPointId,pointId,'5m');                    
    }

    function removeAxis(s,ri,r){
        var pointId = r.get('id');
        var theAxis = charts.get('axis'+mainPointId + pointId);
        if (theAxis !== null)
            theAxis.remove();
    }
    
    function addSeries(s, ri, r) {
        var pointName = r.get('name');
        var pointId = r.get('id');
        //alert(charts.series.length);
        if (charts.series.length > 5) {
            Ext.Msg.alert('系统提示', '最多只能添加5个监测点');
            s.deselectRow(ri);
            return;
        }
        charts.addSeries({
            name: pointName,
            id: 's5'+mainPointId + pointId,            
            data: []
        });
        charts.series[charts.series.length-1].pointId = pointId;
        request5mData(charts, charts.series.length-1, mainPointId,pointId,'5m');
    }

    function removeSeries(s, ri, r) {        
        var pointId = r.get('id');
        var theSeries = charts.get('s5'+mainPointId + pointId);
        if (theSeries !== null)
            theSeries.remove();
    }    
    
    var checkboxSelSuperior = new Ext.grid.CheckboxSelectionModel();
    checkboxSelSuperior.on("rowselect", addAxis);
    checkboxSelSuperior.on("rowdeselect", removeAxis);
    var superiorPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelSuperior,
        autoExpandColumn: 'SuperiorName',
        store: stores.storeSuperior,
        columns: [
            checkboxSelSuperior,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'SuperiorName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });

    var checkboxSelJunior = new Ext.grid.CheckboxSelectionModel();
    checkboxSelJunior.on("rowselect", addAxis);
    checkboxSelJunior.on("rowdeselect", removeAxis);
    var juniorPointPanel = new Ext.grid.GridPanel({
        sm:checkboxSelJunior,
        store: stores.storeJunior,
        autoExpandColumn: 'JuniorName',
        columns: [
            checkboxSelJunior,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'JuniorName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });


    var checkboxSelSibling = new Ext.grid.CheckboxSelectionModel();
    checkboxSelSibling.on("rowselect", addSeries);
    checkboxSelSibling.on("rowdeselect", removeSeries);
    var siblingPointPanel = new Ext.grid.GridPanel({
        sm:checkboxSelSibling,
        store: stores.storeSibling,
        autoExpandColumn: 'SiblingName',
        columns: [
            checkboxSelSibling,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'SiblingName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });
    var eastConnectPointPanel = new Ext.TabPanel({
        width: '30%',
        region: 'east',
        items: [
            {title: '上级监测点', layout: 'fit', items: [superiorPointPanel]},
            {title: '下级监测点', layout: 'fit', items: [juniorPointPanel]},
            {title: '同级监测点', layout: 'fit', items: [siblingPointPanel]}
        ],
        activeTab: 0
    });
    var tab = tabs.add({
        title: vid,
        closable: true,
        id: 'tfive'+mainPointId,
        layout: 'border',
        tbar: [
            {
                xtype: 'datefield',
                format: 'Y年m月d日',
                id:'datefive'+mainPointId,
                width: 150,
                value: now
            },
            {
                xtype: 'button',
                text: '刷新',
                iconCls: 'icon-refresh',
                width: 60,
                style: {marginLeft: '20px'},
                handler: function() {                    
                    var dateTo = Ext.getCmp('datefive' + mainPointId).getValue();
                    
                    for(var i=0;i<charts.series.length;i++){
                        request5mData(charts, i, mainPointId,charts.series[i].pointId,'5m');
                    }
                }
            }
        ],
        items: [middle5mPanel, eastConnectPointPanel]
    });
    stores.storeSuperior.load({params: {id: mainPointId}});
    stores.storeSibling.load({params: {id: mainPointId}});
    stores.storeJunior.load({params: {id: mainPointId}});


    tab.show();

    var charts = new Highcharts.Chart({
        chart: {
            renderTo: 'chartfive'+mainPointId,
            type: 'line'
        },
        title: {
            text: '监测点5分钟电压值对比'
        },
        credits: {
            enabled: false
        },
        colors: [
            '#000000', //黑  
            '#FF0000', //红  
            '#00FF00', //绿  
            '#0000FF', //蓝  
            '#FFFF00', //黄  
            '#FF00FF', //紫  
            '#00FFFF' //  
        ],
        plotOptions: {
            series: {
                lineWidth: 1
            }
        },
        xAxis: {
            title:'时间'
        },
        yAxis: {
            title: {
                text: '电压值(V)'
            }
        },
        series: [{
                name: mainPointName,
                data: [1,2,3,4,5,6,7,8]
            }]
    });
    
    charts.xAxis[0].setCategories(create5MCategoryArray());
    charts.series[0].pointId = mainPointId;
    request5mData(charts, 0, mainPointId,mainPointId,'5m');

}

function dateDiff(dateFrom, dateTo) {
    var tmp = dateTo.getTime() - dateFrom.getTime();
    var day = tmp / 1000 / 60 / 60 / 24;
    return day;
}
function createDayCategoryArray(dateFrom, dateTo) {
    var days = dateDiff(dateFrom, dateTo) + 1;
    var time = dateFrom;
    var categories = [];
    for (var i = 0; i < days; i++) {
        var stime = time.format('Y/m/d');
        categories.push(stime);
        time = time.add(Date.DAY, 1);
    }
    return categories;
}




function requestDayData(charts, i, mainPointId,pointId,cmd) {
    var dateFrom = Ext.getCmp('DateFrom'+mainPointId).getValue().format('Ymd');
    var dateTo = Ext.getCmp('DateTo'+mainPointId).getValue().format('Ymd');
    Ext.Ajax.request({
        url: '../../../servlet/data/HighChartsDataServlet',
        success: function(response, options) {
            var obj = Ext.decode(response.responseText);
            charts.series[i].setData(obj);
        },
        failure: function(response, opts) {
            Ext.Msg.alert('系统提示', '加载数据错误: ' + response.status);
        },
        params: {pointId: pointId,cmd:cmd,dateFrom:dateFrom,dateTo:dateTo}
    });
}

function requestMonthData(charts, i, mainPointId,pointId,cmd) {
    var dateFrom = Ext.getCmp('MonthFrom'+mainPointId).getValue().format('Ym');
    var dateTo = Ext.getCmp('MonthTo'+mainPointId).getValue().format('Ym');
    Ext.Ajax.request({
        url: '../../../servlet/data/HighChartsDataServlet',
        success: function(response, options) {
            var obj = Ext.decode(response.responseText);
            charts.series[i].setData(obj);
        },
        failure: function(response, opts) {
            Ext.Msg.alert('系统提示', '加载数据错误: ' + response.status);
        },
        params: {pointId: pointId,cmd:cmd,dateFrom:dateFrom,dateTo:dateTo}
    });
}
function createMonthCategoryArray(dateFrom, dateTo) {
    var iDateTo = parseInt(dateTo.format('Ym'));    
    var year = parseInt(dateFrom.format('Y'));
    var month=parseInt(dateFrom.format('m'));
    var categories = [];
    while(year*100+month<=iDateTo) {        
        categories.push(year+'/'+month);
        if(month+1>12){
            year = year+1;
            month=1;
        }else{
            month=month+1;
        }
    }
    return categories;
}

function showMonthRateChart(){
    var charts;
    var record = checkboxSel.getSelected();
    var mainPointId = record.get('id');   //主窗口选择的监测点的Id
    var mainPointName = record.get('name');
  

    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择监测点");
        return;
    }

    var stores = createConnectPointStore();
    function addDayRateSeries(s, ri, r) {
        var pointName = r.get('name');
        var pointId = r.get('id');
        //alert(charts.series.length);
        if (charts.series.length > 5) {
            Ext.Msg.alert('系统提示', '最多只能添加5个监测点');
            s.deselectRow(ri);
            return;
        }
        charts.addSeries({
            name: pointName,
            id: mainPointId + pointId,            
            data: []
        });
        charts.series[charts.series.length-1].pointId = pointId;
        requestMonthData(charts, charts.series.length-1, mainPointId,pointId,'month');
    }

    function removeDayRateSeries(s, ri, r) {        
        var pointId = r.get('id');
        var theSeries = charts.get(mainPointId + pointId);
        if (theSeries !== null)
            theSeries.remove();
    }    
    var vid = mainPointName + ' 月合格率对比';

    var monthRateChartPanel = new Ext.Panel({
        width: '70%',
        region: 'center',
        html: '<div id="monthratechart' + mainPointId + '" style="min-width: 200px; height: 400px; margin: 0 auto"></div>'
    });

    var checkboxSelSuperior = new Ext.grid.CheckboxSelectionModel();
    checkboxSelSuperior.on("rowselect", addDayRateSeries);
    checkboxSelSuperior.on("rowdeselect", removeDayRateSeries);
    var superiorPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelSuperior,
        autoExpandColumn: 'SuperiorName',
        store: stores.storeSuperior,
        columns: [
            checkboxSelSuperior,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'SuperiorName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });


    var checkboxSelJunior = new Ext.grid.CheckboxSelectionModel();
    checkboxSelJunior.on("rowselect", addDayRateSeries);
    checkboxSelJunior.on("rowdeselect", removeDayRateSeries);
    var juniorPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelJunior,
        store: stores.storeJunior,
        autoExpandColumn: 'JuniorName',
        columns: [
            checkboxSelJunior,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'JuniorName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });

    var checkboxSelSibling = new Ext.grid.CheckboxSelectionModel();
    checkboxSelSibling.on("rowselect", addDayRateSeries);
    checkboxSelSibling.on("rowdeselect", removeDayRateSeries);
    var siblingPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelSibling,
        store: stores.storeSibling,
        autoExpandColumn: 'SiblingName',
        columns: [
            checkboxSelSibling,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'SiblingName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });
    var eastConnectPointPanel = new Ext.TabPanel({
        width: '30%',
        region: 'east',
        items: [
            {title: '上级监测点', layout: 'fit', items: [superiorPointPanel]},
            {title: '下级监测点', layout: 'fit', items: [juniorPointPanel]},
            {title: '同级监测点', layout: 'fit', items: [siblingPointPanel]}
        ],
        activeTab: 0
    });
    var tab = tabs.add({
        title: vid,
        closable: true,
        id: 'tm' + mainPointId,
        layout: 'border',
        tbar: [
            {
                xtype: 'datefield',
                id: 'MonthFrom' + mainPointId,
                format: 'Y年m月',
                style: {marginLeft: '10px'},
                width: 150,
                value: now.add(Date.MONTH, -12)
            },
            {
                xtype: 'datefield',
                id: 'MonthTo' + mainPointId,
                format: 'Y年m月',
                style: {marginLeft: '20px'},
                width: 150,
                value: now
            },
            {
                xtype: 'button',
                text: '刷新',
                iconCls: 'icon-refresh',
                width: 60,
                style: {marginLeft: '20px'},
                handler: function() {
                    var dateFrom = Ext.getCmp('MonthFrom' + mainPointId).getValue();
                    var dateTo = Ext.getCmp('MonthTo' + mainPointId).getValue();
                    charts.xAxis[0].setCategories(createDayCategoryArray(dateFrom, dateTo));                   
                    for(var i=0;i<charts.series.length;i++){
                        requestMonthData(charts, i, mainPointId,charts.series[i].pointId,'month');
                    }
                }
            }
        ],
        items: [monthRateChartPanel, eastConnectPointPanel]
    });
    stores.storeSuperior.load({params: {id: mainPointId}});
    stores.storeSibling.load({params: {id: mainPointId}});
    stores.storeJunior.load({params: {id: mainPointId}});


    tab.show();

    var charts = new Highcharts.Chart({
        chart: {
            renderTo: 'monthratechart' + mainPointId,
            type: 'spline'
        },
        title: {
            text: '监测点月合格率对比'
        },
        credits: {
            enabled: false
        },
        colors: [
            '#000000', //黑  
            '#FF0000', //红  
            '#00FF00', //绿  
            '#0000FF', //蓝  
            '#FFFF00', //黄  
            '#FF00FF', //紫  
            '#00FFFF' //  
        ],
        xAxis: {
            title: {
                text: '日期'
            }
        },
        yAxis: {
            title: {
                text: '合格率(%)'
            },
            ceiling:102,
            floor:50
            
        },
        series: [{
                name: mainPointName,                
                data: []
            }
        ]
    });
    var dateFrom = Ext.getCmp('MonthFrom' + mainPointId).getValue();
    var dateTo = Ext.getCmp('MonthTo' + mainPointId).getValue();
    charts.xAxis[0].setCategories(createMonthCategoryArray(dateFrom, dateTo));
    charts.series[0].pointId = mainPointId;
    requestMonthData(charts, 0, mainPointId,mainPointId,'month');
}

function showDayRateChart() {
    var charts;
    var record = checkboxSel.getSelected();
    var mainPointId = record.get('id');   //主窗口选择的监测点的Id
    var mainPointName = record.get('name');
  

    if (checkboxSel.getSelections().length === 0) {
        Ext.Msg.alert("系统提示", "您还没有选择监测点");
        return;
    }

    var stores = createConnectPointStore();
    function addDayRateSeries(s, ri, r) {
        var pointName = r.get('name');
        var pointId = r.get('id');
        //alert(charts.series.length);
        if (charts.series.length > 5) {
            Ext.Msg.alert('系统提示', '最多只能添加5个监测点');
            s.deselectRow(ri);
            return;
        }
        charts.addSeries({
            name: pointName,
            id: mainPointId + pointId,            
            data: []
        });
        charts.series[charts.series.length-1].pointId = pointId;
        requestDayData(charts, charts.series.length-1, mainPointId,pointId,'date');
    }

    function removeDayRateSeries(s, ri, r) {
        var pointName = r.get('name');
        var pointId = r.get('id');
        var theSeries = charts.get(mainPointId + pointId);
        if (theSeries !== null)
            theSeries.remove();
    }

    
    var vid = mainPointName + ' 日合格率对比';

    var dayRateChartPanel = new Ext.Panel({
        width: '70%',
        region: 'center',
        html: '<div id="dayratechart' + mainPointId + '" style="min-width: 200px; height: 400px; margin: 0 auto"></div>'
    });

    var checkboxSelSuperior = new Ext.grid.CheckboxSelectionModel();
    checkboxSelSuperior.on("rowselect", addDayRateSeries);
    checkboxSelSuperior.on("rowdeselect", removeDayRateSeries);
    var superiorPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelSuperior,
        autoExpandColumn: 'SuperiorName',
        store: stores.storeSuperior,
        columns: [
            checkboxSelSuperior,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'SuperiorName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });


    var checkboxSelJunior = new Ext.grid.CheckboxSelectionModel();
    checkboxSelJunior.on("rowselect", addDayRateSeries);
    checkboxSelJunior.on("rowdeselect", removeDayRateSeries);
    var juniorPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelJunior,
        store: stores.storeJunior,
        autoExpandColumn: 'JuniorName',
        columns: [
            checkboxSelJunior,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'JuniorName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });

    var checkboxSelSibling = new Ext.grid.CheckboxSelectionModel();
    checkboxSelSibling.on("rowselect", addDayRateSeries);
    checkboxSelSibling.on("rowdeselect", removeDayRateSeries);
    var siblingPointPanel = new Ext.grid.GridPanel({
        sm: checkboxSelSibling,
        store: stores.storeSibling,
        autoExpandColumn: 'SiblingName',
        columns: [
            checkboxSelSibling,
            {header: "ID", sortable: true, dataIndex: "id", hidden: true},
            {header: '监测点名称', id: 'SiblingName', width: 100, sortable: true, dataIndex: 'name'}
        ],
        loadMask: true
    });
    var eastConnectPointPanel = new Ext.TabPanel({
        width: '30%',
        region: 'east',
        items: [
            {title: '上级监测点', layout: 'fit', items: [superiorPointPanel]},
            {title: '下级监测点', layout: 'fit', items: [juniorPointPanel]},
            {title: '同级监测点', layout: 'fit', items: [siblingPointPanel]}
        ],
        activeTab: 0
    });
    var tab = tabs.add({
        title: vid,
        closable: true,
        id: 't' + mainPointId,
        layout: 'border',
        tbar: [
            {
                xtype: 'datefield',
                id: 'DateFrom' + mainPointId,
                format: 'Y年m月d日',
                style: {marginLeft: '10px'},
                width: 150,
                value: now.add(Date.DAY, -15)
            },
            {
                xtype: 'datefield',
                id: 'DateTo' + mainPointId,
                format: 'Y年m月d日',
                style: {marginLeft: '20px'},
                width: 150,
                value: now
            },
            {
                xtype: 'button',
                text: '刷新',
                iconCls: 'icon-refresh',
                width: 60,
                style: {marginLeft: '20px'},
                handler: function() {
                    var dateFrom = Ext.getCmp('DateFrom' + mainPointId).getValue();
                    var dateTo = Ext.getCmp('DateTo' + mainPointId).getValue();
                    charts.xAxis[0].setCategories(createDayCategoryArray(dateFrom, dateTo));                   
                    for(var i=0;i<charts.series.length;i++){
                        requestDayData(charts, i, mainPointId,charts.series[i].pointId,'date');
                    }
                }
            }
        ],
        items: [dayRateChartPanel, eastConnectPointPanel]
    });
    stores.storeSuperior.load({params: {id: mainPointId}});
    stores.storeSibling.load({params: {id: mainPointId}});
    stores.storeJunior.load({params: {id: mainPointId}});


    tab.show();

    var charts = new Highcharts.Chart({
        chart: {
            renderTo: 'dayratechart' + mainPointId,
            type: 'spline'
        },
        title: {
            text: '监测点日合格率对比'
        },
        credits: {
            enabled: false
        },
        colors: [
            '#000000', //黑  
            '#FF0000', //红  
            '#00FF00', //绿  
            '#0000FF', //蓝  
            '#FFFF00', //黄  
            '#FF00FF', //紫  
            '#00FFFF' //  
        ],
        xAxis: {
            title: {
                text: '日期'
            }
        },
        yAxis: {
            title: {
                text: '合格率(%)'
            },
            ceiling:102,
            floor:50
            
        },
        series: [{
                name: mainPointName,                
                data: []
            }
        ]
    });
    var dateFrom = Ext.getCmp('DateFrom' + mainPointId).getValue();
    var dateTo = Ext.getCmp('DateTo' + mainPointId).getValue();
    charts.xAxis[0].setCategories(createDayCategoryArray(dateFrom, dateTo));
    charts.series[0].pointId = mainPointId;
    requestDayData(charts, 0, mainPointId,mainPointId,'date');

}

var columns = [
    {header: "ID", sortable: true, dataIndex: "id", hidden: true},
    {header: "状态", dataIndex: 'startStatus', width: 40,
        renderer: function(v, metaData, record, rowIndex, colIndex, store) {
            var value = parseInt(v);
            var imageName;
            if (value > 0) {
                imageName = 'record_green.png';
                return "<image src='" + basePath + "image/icon/" + imageName + "'/>";
            } else
                imageName = 'record_red.png';
            return "<image src='" + basePath + "image/icon/" + imageName + "'/>";
        }
    },
    {header: '供电局', width: 100, sortable: true, dataIndex: 'company'},
    {header: '部门分县局', width: 100, sortable: true, dataIndex: 'subCompany'},
    {header: '监测点编码', width: 100, sortable: true, dataIndex: 'code'},
    {header: '监测点名称', width: 100, sortable: true, dataIndex: 'name'},
    {header: '监测点类型', width: 80, sortable: true, dataIndex: 'pointType'},
    {header: '电网类型', width: 60, sortable: true, dataIndex: 'pointType2'},
    {header: '上报观测', width: 60, sortable: true, dataIndex: 'reportStatusCh'},
    {header: '电压等级', width: 100, sortable: true, dataIndex: 'voltageLevelName', align: 'right'},
    {header: '电压上限', width: 100, sortable: true, dataIndex: 'upperLimit', xtype: 'numbercolumn', format: '0.00', align: 'right'},
    {header: '电压下限', width: 100, sortable: true, dataIndex: 'lowerLimit', xtype: 'numbercolumn', format: '0.00', align: 'right'},
    {header: '测点地域', width: 100, sortable: true, dataIndex: 'pointArea'},
    {header: '测点位置', width: 100, sortable: true, dataIndex: 'pointPosition'},
    {header: '供电所', width: 100, sortable: true, dataIndex: 'shortName'},
    {header: '所属变电站电压等级', width: 120, sortable: true, dataIndex: 'stationVoltageLevel'},
    {header: '用户名称', width: 120, sortable: true, dataIndex: 'userName'},
    {header: '公变名称', width: 120, sortable: true, dataIndex: 'publicName'},
    {header: '安装位置', width: 120, sortable: true, dataIndex: 'installSite'}
];
var checkboxSel = new Ext.grid.CheckboxSelectionModel({singleSelect: true});
var store;
function buildWindow() {
    store = new Ext.data.JsonStore({
        url: loadPointServlet,
        root: 'data',
        idProperty: 'id',
        totalProperty: 'count',
        fields: fieldName,
        autoLoad: true,
        baseParams: {start: 0, limit: _pageSize, cmd: "connection"}
    });

    var grid = new Ext.grid.GridPanel({
        //title: _title,
        store: store,
        sm: checkboxSel,
        columns: [checkboxSel].concat(columns),
        loadMask: true,
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: '目前没有信息'
        })
    });
    Ext.getCmp('main-tab').add(grid);
    var applicationUI = new Ext.Viewport({
        layout: "fit",
        items: [
            tabs
        ]
    });

}
Ext.onReady(buildWindow);
